#include "user_functions.h"

using std::exception;

big_int factorial(big_int n)
{
	if (n < big_int(0))
		throw exception();
	big_int result(1);
	for (big_int i(1); i <= n; i += big_int(1))
		result *= i;
	return result;
}
namespace
{
	struct initializer_factorial
	{
		initializer_factorial()
		{
			get_functions()["fact"] = functions("fact", factorial);	
		}
	};
		
	initializer_factorial factorial_;
};

big_int sqr(big_int a)
{
	return a * a;
}
namespace
{
	struct initializer_sqr
	{
		initializer_sqr()
		{
			get_functions()["sqr"] = functions("sqr", sqr);	
		}
	};
		
	initializer_sqr sqr_;
};

big_int digits(big_int a)
{
	return a.size();
}
namespace
{
	struct initializer_digits
	{
		initializer_digits()
		{
			get_functions()["digits"] = functions("digits", digits);	
		}
	};
		
	initializer_digits digits_;
};